
import requests


class SendDDMsg(object):

    def __init__(self):
        self.token = None

    def getToken(self):
        caseName = ''
        if caseName.find('online') > -1:
            self.token = ''   #等后期在环境变量里取
        else:
            self.token = ''

    def sendMsg(self, msg):
        self.getToken()
        #初始化Webhook
        url = 'https://oapi.dingtalk.com/robot/send?access_token={}'.format(self.token)
        #初始化消息头
        header = {
            "Content-Type": "application/json",
            "Charset": "UTF-8"
        }
        #初始化消息体
        jsonMsg = {
            "at": {
                "atMobiles": [],
                "atUserIds": ["u9ffvos"],
                "isAtAll": False
            },
            "text": {
                "content": msg
            },
            "msgtype": "text"
        }
        #发送消息
        requests.post(url=url, json=jsonMsg, headers=header)



